<?php
namespace Admin\Controller;
use Think\Controller;
use Common\Common\Tree;
class CategoryController extends Controller {
    public function index(){
    	$model = M('category');
    	$categorys = $model->select();
    	$obj = new Tree();
    	$categorys = $obj->reload($categorys);
    	// exit;
    	$this->assign('categorys',$categorys);
    	$this->display();
    }

    public function add()
    {
    	if(IS_POST){

    		$data['fid'] = I('post.fid',0);
    		$data['cname'] = I('post.cname');
    		$model = M('category');
    		$res = $model->add($data);
    		if($res){
    			$this->success('增加成功',U('Admin/Category/index'));
    		}else{
    			$this->error('增加失败',U('Admin/Category/index'));
    		}
    		
    	}else{

    		$this->error('非法请求',U('Admin/Category/index'));
    	}
    }
}
?>